package com.news.gpb.controller;


import com.news.gpb.entity.Coll;
import com.news.gpb.entity.Like;
import com.news.gpb.entity.News;
import com.news.gpb.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@CrossOrigin("http://localhost:8080")
@RestController
public class NewsController {

    @Autowired
    NewsService newsService;

    @RequestMapping("/index")
    public List<News> getNewsList(@RequestBody News news)
    {
        return newsService.getNewsList(news);
    }
    @RequestMapping("/hotlist")
    public List<News> getHotList()
    {
        return newsService.getHotList();
    }

    @RequestMapping("/all")
    public List<News> getAllList(@RequestBody News news)
    {
        return newsService.getAllList(news);
    }

    @RequestMapping(value = "/getNew/{news_id}",method = RequestMethod.GET)
    public News getNew(@PathVariable int news_id)
    {
        return newsService.getNewsDetail(news_id);
    }

    @RequestMapping("updateViews")
    public Integer updateViews(@RequestBody News news)
    {
        return newsService.updateViews(news);
    }

    @RequestMapping("like")
    public String getLike(@RequestBody Like like)
    {
        return newsService.getLike(like);
    }

    @RequestMapping("likeUp")
    public String updateLikesUp(@RequestBody Like like)
    {
        return newsService.likeUp(like);
    }

    @RequestMapping("likeDown")
    public String updateLikesDown(@RequestBody Like like)
    {
        return newsService.likeDown(like);
    }

    @RequestMapping("collect")
    public String getCollect(@RequestBody Coll coll)
    {
        return newsService.getCollect(coll);
    }

    @RequestMapping("collectUp")
    public String updateCollectUp(@RequestBody Coll coll) { return newsService.collectUp(coll); }

    @RequestMapping("collectDown")
    public String updateCollectDown(@RequestBody Coll coll)
    {
        return newsService.collectDown(coll);
    }

    @RequestMapping("myLike")
    List<News> getMyLike(@RequestBody Like like)
    {
        return newsService.getMyLike(like.getUser_id());
    }

    @RequestMapping("myCollect")
    List<News> getMyCollect(@RequestBody Like like)
    {
        return newsService.getMyCollect(like.getUser_id());
    }
}
